package com.hx.study.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.hx.common.annotation.Log;
import com.hx.common.core.controller.BaseController;
import com.hx.common.core.domain.AjaxResult;
import com.hx.common.core.page.TableDataInfo;
import com.hx.common.enums.BusinessType;
import com.hx.common.utils.poi.ExcelUtil;
import com.hx.study.domain.PaperRepository;
import com.hx.study.service.IPaperRepositoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 考试题库Controller
 *
 * @author user
 * @date 2022-06-06
 */
@RestController
@RequestMapping("/exam/paperRepository")
public class PaperRepositoryController extends BaseController {
    @Autowired
    private IPaperRepositoryService paperRepositoryService;

    /**
     * 查询考试题库列表
     */
    @PreAuthorize("@ss.hasPermi('exam:paperRepository:list')")
    @GetMapping("/list")
    public TableDataInfo list(PaperRepository paperRepository) {
        startPage();
        List<PaperRepository> list = paperRepositoryService.selectPaperRepositoryList(paperRepository);
        return getDataTable(list);
    }

    /**
     * 导出考试题库列表
     */
    @PreAuthorize("@ss.hasPermi('exam:paperRepository:export')")
    @Log(title = "考试题库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PaperRepository paperRepository) {
        List<PaperRepository> list = paperRepositoryService.selectPaperRepositoryList(paperRepository);
        ExcelUtil<PaperRepository> util = new ExcelUtil<PaperRepository>(PaperRepository.class);
        util.exportExcel(response, list, "考试题库数据");
    }

    /**
     * 获取考试题库详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:paperRepository:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(paperRepositoryService.selectPaperRepositoryById(id));
    }

    /**
     * 新增考试题库
     */
    @PreAuthorize("@ss.hasPermi('exam:paperRepository:add')")
    @Log(title = "考试题库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaperRepository paperRepository) {
        return toAjax(paperRepositoryService.insertPaperRepository(paperRepository));
    }

    /**
     * 修改考试题库
     */
    @PreAuthorize("@ss.hasPermi('exam:paperRepository:edit')")
    @Log(title = "考试题库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PaperRepository paperRepository) {
        return toAjax(paperRepositoryService.updatePaperRepository(paperRepository));
    }

    /**
     * 删除考试题库
     */
    @PreAuthorize("@ss.hasPermi('exam:paperRepository:remove')")
    @Log(title = "考试题库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(paperRepositoryService.deletePaperRepositoryByIds(ids));
    }
}
